<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>统计数据</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">统计数据</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <form class="form-inline">
                    <div class="form-group">
                        <label>查询时间：</label>
                        <select  class="form-control" id="accountCode" >
                            <option value="">全部</option>
                        </select>&nbsp;&nbsp;

                        <div class="form-group">
                            <!--<label>时间:</label>-->
                            <input type="text" id="startDate" style="padding-left:3px;width: 150px;" class="form-control" placeholder="开始时间" data-format="yyyy-MM-dd">
                        </div>
                        <div class="form-group">
                            <label>至</label>
                        </div>
                        <div class="form-group">
                            <input type="text" id="endDate" style="padding-left:3px;width: 150px;" class="form-control" placeholder="结束时间" data-format="yyyy-MM-dd">
                        </div>
                    </div>
                    <div class="form-group">
                        <button type="button"  onclick="getData()"  class="btn btn-block btn-primary glyphicon glyphicon-search">搜索</button>
                    </div>


                    <div class="form-group">
                        <div class="form-group" style="margin-right: 20px;margin-left: 5px;">
                            <button type="button" onclick="exportData()" class="btn btn-block btn-primary glyphicon glyphicon-download-alt">导出数据</button>
                        </div>
                    </div>
                </form>
            </div>

            <div class="box-body" style="height:100%;">
                <table id="dataList" class="table table-bordered table-hover" >
                    <thead>
                    <tr>
                        <th>渠道号</th>
                        <th>日期</th>
                        <th>总注册数</th>
                        <th>实名通过数</th>
                        <th>未实名数</th>
                    </tr>
                    </thead>
                    <tbody >
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>


<!-- page script -->
<script>
    $(document).ready(function() {
        //加载数据
        getData();
        initAgent();
    });
    //日期插件相关
    $.datetimepicker.setLocale('zh');
    $("#startDate").datetimepicker({
        inline:false,	//true-显示，false - 隐藏
        format: 'Y-m-d',
        timepicker: false, //true-显示时间，false - 不显示时间
        height : "50px",
        value: calcDateByDay(new Date(), 'yyyy-MM-dd', -30)
        // minDate : 0 //最小日期今天
    });

    $("#endDate").datetimepicker({
        inline:false,	//true-显示，false - 隐藏
        format: 'Y-m-d',
        timepicker: false, //true-显示时间，false - 不显示时间
        height : "50px",
        value: new Date()
        // minDate : 0 //最小日期今天
    });

    // 加载数据
    function getData(){
        var table = $('#dataList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "bPaginate": false, //开关，是否显示分页器
            "bLengthChange": false, //开关，是否显示每页显示多少条数据的下拉框
            "ajax" :  {
                url:"/agent/getStaticTotal",
                type:"POST",
                data:{
                   // agentCode : agentCode,
                    code : $("#accountCode").val(),
                    startDate : $("#startDate").val(),
                    endDate : $("#endDate").val()
                }
            },
            //参数显示
            "columns": [
                {"data": "channel", 'sClass': "text-center",'width': '7%'},
                {"data": "createTime", 'sClass': "text-center",'width': '6%'},
                {"data": "registerTotal", 'sClass': "text-center",'width': '5%'},
                {"data": "passTotal", 'sClass': "text-center",'width': '5%'},
                {"data": "notPassTotal", 'sClass': "text-center",'width': '5%'}
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    //初始化下来选择渠道商
    function initAgent() {
        $.ajax({
            type:"POST",
            url:"/agent/getAllAgent",
            async : true,//默认就是true
            dataType:"json",
            data:{},
            success : function(res) {
                for (var i = 0; i <res.data.length ; i++) {
                    $("#accountCode").append("<option value='"+res.data[i].code +"'>"+res.data[i].account+"</option>");
                }
            }
        });
    }

    //导出数据
    function exportData() {
        code = $("#accountCode").val();
        startDate  = $("#startDate").val();
        endDate  = $("#endDate").val();
        window.location.href="/agent/exportExcel?code="+code+"&startDate="+startDate+"&endDate="+endDate;
    }

</script>
</body>
</html>
